package mall;

import mall.repository.ConfigRepository;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @author xf07b1
 * @wechat xf07b1
 * @description
 */
@WebListener
public class StartupListener implements ServletContextListener {

    private final ConfigRepository configRepository = new ConfigRepository();

    @Override
    public void contextInitialized(ServletContextEvent sce) {

        ServletContext context = sce.getServletContext();

        // 系统配置
        context.setAttribute("systemName", getConfigValue("system.name"));
        context.setAttribute("systemAbout", getConfigValue("system.about"));
        context.setAttribute("adminSystemName", getConfigValue("admin.system.name"));



        ServletContextListener.super.contextInitialized(sce);
    }


    private String getConfigValue(String key) {
        return configRepository.selectByKey(key).getValue();
    }
}
